﻿#include <iostream> 

#include <fbxsdk.h>
#include "./Common/Common.h"

#define SAMPLE_FILENAME_MC		"ExportScene00.fbx"


// 创建三角网格
FbxNode* CreateTriangleMesh(FbxManager* pManager, const char* pName)
{
    // 创建网格
    FbxMesh* lMesh = FbxMesh::Create(pManager, pName);

    // 设置顶点坐标
    lMesh->InitControlPoints(3);
    FbxVector4* lControlPoints = lMesh->GetControlPoints();
    lControlPoints[0] = FbxVector4(0, 0, 0);
    lControlPoints[1] = FbxVector4(1, 0, 0);
    lControlPoints[2] = FbxVector4(0, 1, 0);

    // 设置三角形面
    lMesh->BeginPolygon();
    lMesh->AddPolygon(0);
    lMesh->AddPolygon(1);
    lMesh->AddPolygon(2);
    lMesh->EndPolygon();

    // 创建节点并将网格添加到节点
    FbxNode* lNode = FbxNode::Create(pManager, pName);
    lNode->SetNodeAttribute(lMesh);

    return lNode;
}

int main(int argc, char** argv) {

    FbxManager* fm = nullptr;
    FbxScene* lScene = nullptr;

    // Prepare the FBX SDK.
    InitializeSdkObjects(fm, lScene);

    // 创建三角形网格
    FbxNode* lTriangleMeshNode = CreateTriangleMesh(fm, "TriangleMesh");

    // 将网格添加到场景
    lScene->GetRootNode()->AddChild(lTriangleMeshNode);

    char* lSampleFileName = (char*)SAMPLE_FILENAME_MC;

    SaveScene(fm, lScene, lSampleFileName);

    DestroySdkObjects(fm, true);

}